/**
 * create by watsonos
 */
var base={};

/* 将form表单内的元素序列化为对象，扩展Jquery的一个方法 */
base.serializeObject = function(form) { 
	var obj = {};
	$.each(form.serializeArray(), function(index) {
		if (obj[this['name']]) {
			obj[this['name']] = obj[this['name']] + "," + this['value'];
		} else {
			obj[this['name']] = this['value'];
		}
	});
	return obj;
};
var interval;
/*表单重复提交按钮设置*/
base.processStatus =function(i,x,y){
	if(i == 1){	//show
		$("#" + x).hide();
		$("#" + y).show();
		var str = $("#" + y).val();
		var j = 0;
		interval=setInterval(function(){
			if(j % 4 == 0){
				$("#" + y).val(str);
			}else{
				$("#" + y).val($("#" + y).val()+".");
			}
			j++;
		},700);
	}else{	//hidden
		if(interval){
			clearInterval(interval);
		}
		$("#" + x).show();
		$("#" + y).hide();
	}
};

//全选
base.selectAll=function(obj,clazz) {
	if ($(obj).attr("checked")) {
		$("."+clazz).attr("checked", "checked");
	} else {
		$("."+clazz).removeAttr("checked");
	}
};

base.setTitle=function(text){
	document.title = text;
}

base.jqPaginator = function(id,page,visiblePages,fun){
	$('#'+id).jqPaginator({
	    totalPages: page.pageTotal,
	    visiblePages: visiblePages,
	    currentPage: page.pageNo,
	    first: '<li><a href="javascript:void(0);">首页</a></li>',
        prev: '<li><a href="javascript:void(0);">上一页</a></li>',
        next: '<li><a href="javascript:void(0);">下一页</a></li>',
        last: '<li><a href="javascript:void(0);">末页</a></li>',
        page: '<li><a href="javascript:void(0);">{{page}}</a></li>',
	    onPageChange: function (num, type) {
	        if (type == 'change') eval(fun+"("+num+")");
	    }
	});
}

base.filterPlace=function(provinceCode,cityCode){
	var place = "";
	if(provinceCode && data){
		for(var i=0,len=data.length;i<len;i++){
			if(provinceCode == data[i]["id"]){
				var province = data[i];
				place += province["name"];
				if(province["cities"]){
					for (var j=0,l=province["cities"].length;j<l;j++){
						if(cityCode == province["cities"][j]["id"]){
							place += province["cities"][j]["name"];
						}
					}							
				}
			}
		}
	}
	return place;
}

Date.prototype.Format = function(fmt)   
{ 
	var obj = {   
			"M+" : this.getMonth()+1,                 //月份   
			"d+" : this.getDate(),                    //日   
			"h+" : this.getHours(),                   //小时   
			"m+" : this.getMinutes(),                 //分   
			"s+" : this.getSeconds(),                 //秒   
			"q+" : Math.floor((this.getMonth()+3)/3), //季度   
			"S"  : this.getMilliseconds()             //毫秒   
	};   
	if(/(y+)/.test(fmt))   
		fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
	for(var k in obj)   
		if(new RegExp("("+ k +")").test(fmt))   
			fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (obj[k]) : (("00"+ obj[k]).substr((""+ obj[k]).length)));   
	return fmt;   
}  



